/*
 * Copyright (c) 2009. Silenus Consultoria, S.L.
 */
package es.silenus.detecta.model;

import java.util.HashSet;
import java.util.Set;


/**
 * Knowledge path. Persistent class, read-write.
 *
 * @author <a href="mailto:malonso@silenus-consultoria.es">Mariano Alonso</a>
 *
 * @since 22-mar-2009 11:04:04
 */
public class KnowledgePath implements java.io.Serializable {
	/**
	 * The identifier.
	 */
	private int id;

	/**
	 * The knowledge path code, must be unique per organization.
	 */
	private String code;

	/**
	 * The description.
	 */
	private String description;

	/**
	 * The parent knowledge area.
	 */
	private KnowledgeArea area;

	/**
	 * The associated knowledge units, to achieve a knowledge path.
	 */
	private Set<KnowledgeUnit> units;

/**
   * Constructor.
   */
	public KnowledgePath() {
		units = new HashSet<KnowledgeUnit>();
	}

	/**
	 * Retrieves the identifier.
	 *
	 * @return the identifier.
	 */
	public int getId() {
		return this.id;
	}

	/**
	 * Sets the identifier.
	 *
	 * @param id the identifier.
	 */
	public void setId(int id) {
		this.id = id;
	}

	/**
	 * Retrieves the code.
	 *
	 * @return the code.
	 */
	public String getCode() {
		return this.code;
	}

	/**
	 * Sets the code.
	 *
	 * @param code the code.
	 */
	public void setCode(final String code) {
		this.code = code;
	}

	/**
	 * Retrieves the description.
	 *
	 * @return the description.
	 */
	public String getDescription() {
		return this.description;
	}

	/**
	 * Sets the description.
	 *
	 * @param description the description.
	 */
	public void setDescription(final String description) {
		this.description = description;
	}

	/**
	 * Retrieves the area.
	 *
	 * @return the area.
	 */
	public KnowledgeArea getArea() {
		return this.area;
	}

	/**
	 * Sets the area.
	 *
	 * @param area the area.
	 */
	public void setArea(final KnowledgeArea area) {
		this.area = area;
	}

	/**
	 * Retrieves the knowledge units.
	 *
	 * @return the knowledge units.
	 */
	public Set<KnowledgeUnit> getUnits() {
		return this.units;
	}

	/**
	 * Sets the knowledge units.
	 *
	 * @param units the knowledge units.
	 */
	public void setUnits(final Set<KnowledgeUnit> units) {
		this.units = units;
	}

	/**
	 * Adds a unit.
	 *
	 * @param unit a unit.
	 */
	public void add(final KnowledgeUnit unit) {
		getUnits().add(unit);
	}

	/**
	 * Removes a unit.
	 *
	 * @param unit a unit.
	 */
	public void remove(final KnowledgeUnit unit) {
		getUnits().remove(unit);
	}

	/**
	 * Checks if objects are equal.
	 *
	 * @param o other object.
	 *
	 * @return true if equal, false otherwise.
	 */
	@Override
	public boolean equals(Object o) {
		if(this == o) {
			return true;
		}

		if(!(o instanceof KnowledgePath)) {
			return false;
		}

		KnowledgePath that = (KnowledgePath)o;

		if(getId() != that.getId()) {
			return false;
		}

		return true;
	}

	/**
	 * Calculates the hash of this instance.
	 *
	 * @return the hash code.
	 */
	@Override
	public int hashCode() {
		return getId();
	}

	/**
	 * Stringifies this instance.
	 *
	 * @return the string representation.
	 */
	@Override
	public String toString() {
		final StringBuilder sb = new StringBuilder();

		sb.append("KnowledgePath");
		sb.append("{id=").append(getId());
		sb.append(", code='").append(getCode()).append('\'');
		sb.append('}');

		return sb.toString();
	}
}
